﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WeChatRobotSDKCommon.Helper
{
    public class StringHelper
    {
        /// <summary>
        /// 根据首尾字符截取字符串
        /// </summary>
        /// <param name="strfull"></param>
        /// <param name="strhead"></param>
        /// <param name="strfoot"></param>
        /// <returns></returns>
        public static string GetSubString(string strfull, string strhead, string strfoot)
        {
            int pos1, pos2;
            string result = "";
            pos1 = strfull.IndexOf(strhead, StringComparison.OrdinalIgnoreCase);
            if (pos1 > -1)
            {
                pos2 = strfull.IndexOf(strfoot, StringComparison.OrdinalIgnoreCase);
                if (pos2 > -1)
                {
                    result = strfull.Substring(pos1 + strhead.Length, pos2 - pos1 - strhead.Length);
                }
            }
            return result;
        }


        /// <summary>
        /// 根据开始字符可往后的字符个数截取字符
        /// </summary>
        /// <param name="strfull"></param>
        /// <param name="strhead"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        public static string GetSubStringByLen(string strfull, string strhead, int len)
        {
            int pos1, pos2;
            string result = "";
            pos1 = strfull.IndexOf(strhead, StringComparison.OrdinalIgnoreCase);
            if (pos1 > -1)
            {
                result = strfull.Substring(pos1 + strhead.Length, pos1 + len);
            }
            return result;
        }



    }
}
